package com.auto.survey.activity.monitoring.modle

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.auto.survey.activity.monitoring.entity.MonitoringPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class DoCollectedViewModle : ViewModel() {

    companion object {
        val KEY_DO_COLLECTED_PASS = "KEY_DO_COLLECTED_PASS"
        val KEY_DO_COLLECTED_MESSAGE = "KEY_DO_COLLECTED_MESSAGE"

        val KEY_MAP_POINT_HZ = "KEY_MAP_POINT_HZ"
        val KEY_MAP_POINT_VA = "KEY_MAP_POINT_VA"
        val KEY_MAP_POINT_SD = "KEY_MAP_POINT_SD"
        val KEY_MAP_POINT_HIGHT = "KEY_MAP_POINT_HIGHT"
        val KEY_MAP_MIRROR_TYPE = "KEY_MAP_MIRROR_TYPE"
        val KEY_MAP_POINT_X = "KEY_MAP_POINT_X"
        val KEY_MAP_POINT_Y = "KEY_MAP_POINT_Y"
        val KEY_MAP_POINT_Z = "KEY_MAP_POINT_Z"
    }
    val state = MutableLiveData<Map<String, Any>>()

    val mPoint = MutableLiveData<MonitoringPoint?>()

    val measureData = MutableLiveData<Map<String, Double>>()

    val faceState = MutableLiveData<String>()

    fun updateFaceMsg(content:String) {
        viewModelScope.launch {
            val result = withContext(Dispatchers.IO) {
                content
            }
            faceState.value = result
        }

    }

    fun updateState(pass:Boolean, msg:String) {
        viewModelScope.launch {
            val result = withContext(Dispatchers.IO){
                val map = HashMap<String, Any>()
                map.put(KEY_DO_COLLECTED_PASS, pass)
                map.put(KEY_DO_COLLECTED_MESSAGE, msg)

                map
            }

            state.value = result
        }
    }

    fun updatePoint(point:MonitoringPoint?) {
        viewModelScope.launch {
            val result = withContext(Dispatchers.IO){
                point
            }
            mPoint.value = result
        }
    }

    fun updateMeasureData(data:Map<String, Double>) {
        viewModelScope.launch {
            val result = withContext(Dispatchers.IO){
                data
            }

            measureData.value = result
        }

    }
}